
module ASK_Demodulator
#(
    parameter WIDTH = 10,
    parameter MAXINTERVAL_WIDTH = 8,
    parameter THRESHOLD_H = 192,
    parameter THRESHOLD_L = 128
)
(
    input wire signed [WIDTH-1:0] i_ASK_Signal,
    input wire [MAXINTERVAL_WIDTH-1:0] i_Interval,
    input wire i_clk,
    input wire i_rst,
    output reg  o_Baseband
);

wire signed [WIDTH-1:0] Envelope;

always@(posedge i_clk or posedge i_rst) begin
    if(i_rst) begin
        o_Baseband<='b0;
    end
    else begin
        if(Envelope>THRESHOLD_H) begin
            o_Baseband<=1'b1;
        end
        else if(Envelope<THRESHOLD_L) begin
            o_Baseband<=1'b0;
        end
        else begin
            o_Baseband<=o_Baseband;
        end
    end
end


Envelope_Detector_Digital 
#(
    .WIDTH(WIDTH),
    .MAXINTERVAL(64),
    .MAXINTERVAL_WIDTH(MAXINTERVAL_WIDTH)
)
ED_ASK
(
    .i_SignalInput(i_AM_Signal),
    .i_Interval(i_Interval),
    .i_clk(i_clk),
    .i_rst(i_rst),
    .o_Envelope(Envelope)
);

endmodule